"""
要领：
1、self本质上是一个参数，哪个对象调用方法，self就是这个对象
2、对象.方法时，优先去创建对象的那个类中寻找方法，没有找到时，根据继承关系向上继续寻找。
3、多继承时，寻找成员时，优先去自己类中寻找，如果没有，先在左边找，左边没有再去右边。
"""
# class Userinfo:
#     def __init__(self,a1,a2):
#         self.username=a1
#         self.pwd=a2
# user_list=[]
# while True:
#     user =input("请输入用户名：")
#     if user.upper()=="Q":
#         break
#     pwd=input("请输入密码：")
#     obj=Userinfo(user,pwd)
#     user_list.append(obj)
# for item in user_list:
#     text=f"用户名：{item.username};密码：{item.pwd}"
#     print(text)


# class Foo:
#     def f1(self):
#         pass
#     def f2(self,a1):
#         return f"{a1}是个好孩子"
#     def f3(self,a1,a2):
#          return a1+a2
#
# obj=Foo()
# obj.f1()
# name=obj.f2("刘朝朋")
# res=obj.f3(5,8)
# text=f"{name}，他今天卖出去{res}个煎饼"
# print(text)

# v1=list()
# v1.append("luyafei")
# print(v1)
# tuple

# class Police:
#     """警察类"""
#     def __init__(self,name,age,hit_points):
#         self.name=name
#         self.age=age
#         self.hit_points=hit_points
#     def catch(self):
#         """抓小偷"""
#         self.hit_points=self.hit_points+500
#     def somking(self):
#         """抽烟"""
#         self.hit_points=self.hit_points-200
#     def shoot(self,user):
#         user.hit_points=user.hit_points-100
#         # if user.hit_points<=0:
#         #     user.name="死亡"
#         self.hit_points=self.hit_points-50
# p1=Police("朱振凯",22,5000)
# p2=Police("陈宏伟",32,10000)
# p3=Police("刘朝朋",30,500)
# print(p1.hit_points)
# p1.catch()
# p2.somking()
# print(p2.hit_points)
# print(p1.hit_points)
# p1.shoot(p3)
# print(p1.hit_points)
# print(p3.hit_points)
# print(p3.name)
# p3.shoot(p1)
# print(p1.hit_points)
# print(p3.hit_points)
# print(p3.name)
# p1.shoot(p3)
# print(p1.hit_points)
# print(p3.hit_points)
# print(p3.name)

# p1.somking()  #4800
# p1.shoot(p2) #p1:4750 p2:9900
# p2.catch()   #p2:10400
# p3.shoot(p1) #p3：450 p1:4650
# p2.shoot(p1) #p2:10350 p1：4550
# print(p1.hit_points,p2.hit_points,p3.hit_points)


# class Police:
#     """警察类"""
#     def __init__(self,name,age,hit_points):
#         self.name=name
#         self.age=age
#         self.hit_points=hit_points
#     def catch(self):
#         """抓小偷"""
#         self.hit_points=self.hit_points+500
#     def somking(self):
#         """抽烟"""
#         self.hit_points=self.hit_points-200
#     def shoot(self,user):
#         user.hit_points=user.hit_points-100
#         # if user.hit_points<=0:
#         #     user.name="死亡"
#         self.hit_points=self.hit_points-50
# class Terriorist:
#     """恐怖分子"""
#     def __init__(self,name,hit_points):
#         self.name=name
#         self.hit_points=hit_points
#     def shoot(self,user):
#         user.hit_points=user.hit_points-1000
#
#     def strafe(self,user_list):
#         for user in user_list:
#             user.hit_points=user.hit_points-200
#
#     def bomb(self,user_list):
#         for user in user_list:
#             user.hit_points=user.hit_points-500
#         self.hit_points=self.hit_points-100
# p1=Police("李元芳",22,5000)
# p2=Police("狄仁杰",35,3000)
# p3=Police("展昭",25,6000)
#
# t1=Terriorist("萨达姆",4000)
# t2=Terriorist("东条英机",3000)
# t3=Terriorist("希特勒",8000)
# t3.shoot(p1)    #t3 8000 p1 4000
# p2.shoot(t3)    #p2 2950 t3 7900
# t2.strafe([p3,p2,t1,t3]) #t2 3000  p3 5800 p2 2750  t1 3800 t3 7700
# t1.bomb([t2,p2,p1])    #t1 3700 t2 2500 p2 2250 p1 3500
# p3.shoot(t2)           #p3 5750 t2 2400
# t1.shoot(p2)           #t1 3700 p2 1250
# t3.bomb([p1,p2,p3])    #t3 7600 p1 3000 p2 750 p3 5250
# p2.shoot(t2)           #p2 700 t2 2300
# p1.catch()             #p1 3500
#
# text1=f"{p1.name}的血量是{p1.hit_points}"
# text2=f"{p2.name}的血量是{p2.hit_points}"
# text3=f"{p3.name}的血量是{p3.hit_points}"
# text4=f"{t1.name}的血量是{t1.hit_points}"
# text5=f"{t2.name}的血量是{t2.hit_points}"
# text6=f"{t3.name}的血量是{t3.hit_points}"
# print(text1,text2,text3,text4,text5,text6)
#
# class Base:
#     def do(self):
#         print("base.do")
#
#     def show(self):
#         print("show")
#         self.do()
# class Son(Base):
#     def do(self):
#         print("do")
# s1=Son()
# s1.show()

# class BaseServer:
#     def run(self):
#         print("RUN")
#         self.f1()
# class TCPServer(BaseServer):
#     def f1(self):
#         print("TCPSercer")
# class ThreadingMixIn:
#     def f1(self):
#         print("ThreadingMixIn")
# class ThreadingTCPServer(ThreadingMixIn,TCPServer):
#     pass
# obj=ThreadingTCPServer()
# obj.run()


#多态
def func(arg):
    # 检查 arg 是否有 send 方法，并且根据方法的签名调用不同的逻辑
    if hasattr(arg, 'send'):
        # 如果是 F2 类的实例，传递两个参数
        if isinstance(arg, F2):
            arg.send(5, 2)  # 这里可以根据需要传递不同的参数
        else:
            arg.send()

class F1:
    def send(self):
        print("今天真是个好天气！")

class F2:
    def __init__(self):
        # 初始化 a 和 b，或者可以在 send 方法中赋值
        self.a = 0
        self.b = 0

    def send(self, a, b):
        self.a = a
        self.b = b
        print(self.a + self.b)

# 创建对象
obj1 = F1()
obj2 = F2()

# 调用 func 函数
func(obj1)
func(obj2)